package wang.aweb.childcar.common;

import com.google.common.collect.Sets;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import wang.aweb.childcar.exception.CarException;
import wang.aweb.childcar.exception.CarExceptionEnum;

import java.util.Set;

@Component
public class Constant {
    public static final String EMAIL_FROM="18395614415@163.com";
    public static final String EMAIL_SUBJECT="您的验证码";
    public static final String JWT_KEY="wangqiang666";
    public static final String USER_NAME="username";
    public static final String USER_ID="id";
    public static final String USER_ROLE="user_role";
    public static final Long EXPIRE_TIME=60*1000*60*24*10l;//单位毫秒目前为10天
    public static final String JWT_TOKEN="JWTToken";
    public static final String SALT="nsjkdgnkjw3uer4r,.";
    public static final String MALL_USER="mall_user";
    public static final Integer IMAGE_SIZE=400;
    public static final Float IMAGE_OPACITY=0.5f;
    public static final String WATER_MARK_JPG="watermark.jpg";
    public static String IMG_DOMAIN;
    public static String FILE_UPLOAD_DIR;
    @Value("${img.domain}")
    public void setImgDomain(String imgDomain) {
        IMG_DOMAIN = imgDomain;
    }

    @Value("${file.upload.dir}")
    public void setFileUploadDir(String fileUploadDir){
        FILE_UPLOAD_DIR=fileUploadDir;
    }
    public interface ProductListOrderBy{
        Set<String> PRICE_ASC_DESC = Sets.newHashSet(
                "price desc","price asc"
        );
    }
    public interface SaleStatus{
        int NOT_SALE=0;
        int SALE=1;
    }
    public interface Cart{
        int UN_CHECKED=0;//购物车未选中状态
        int CHECKED=1;//购物车选中状态
    }
    public enum OrderStatusEnum{
        CANCELED(0,"用户已取消"),
        NOT_PAID(10,"未付款"),
        PAID(20,"已付款"),
        DELIVERED(30,"已发货"),
        FINISHED(40,"交易已完成");

        private String value;
        private int code;
        OrderStatusEnum(int code,String value){
            this.value=value;
            this.code=code;
        }
        public static OrderStatusEnum codeOf(int code){
            for(OrderStatusEnum orderStatusEnum:values()){
                if(orderStatusEnum.getCode()==code){
                    return orderStatusEnum;
                }
            }
            throw new CarException(CarExceptionEnum.NO_ENUM);
        }
        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }
    }
}
